package com.zjpavt.client.util;

public class MathUtil {

    private static String hexStr = "0123456789abcdef";
    private static String[] binaryArray = {
        "0000", "0001", "0010", "0011",
        "0100", "0101", "0110", "0111",
        "1000", "1001", "1010", "1011",
        "1100", "1101", "1110", "1111"
    };

    /**
     * @param hexString 16进制字符串
     * @return 将十六进制转换为二进制
     */
    public static String HexStringToBinaryString(String hexString) throws NumberFormatException {
        StringBuilder res = new StringBuilder();
        int len = hexString.length();
        for (int i = 0; i < len; i++) {
            int pos = hexStr.indexOf(hexString.charAt(i));
            if (pos == -1) {
                throw new NumberFormatException("Input HexString Invalid");
            }
            res.append(binaryArray[pos]);
        }
        return res.toString();
    }

}
